package a.location;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class MyLocation extends ItemizedOverlay<OverlayItem> {
    private ArrayList<OverlayItem> locations = new ArrayList<OverlayItem>();

    public MyLocation(Drawable marker) {
        super(marker);
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        // Hide the shadow by setting shadow to false
        shadow = false;
        super.draw(canvas, mapView, shadow);
    }

    @Override
    protected OverlayItem createItem(int i) {
        return locations.get(i);
    }

    @Override
    public int size() {
        return locations.size();
    }

    public void add(OverlayItem item) {
        locations.add(item);
        populate();
    }

    public void add(OverlayItem item, boolean refresh) {
        locations.add(item);
        if (refresh) {
            populate();
        }
    }

    public void remove(OverlayItem item) {
        locations.remove(item);
        populate();
    }

    public void remove(OverlayItem item, boolean refresh) {
        locations.remove(item);
        if (refresh) {
            populate();
        }
    }

    public void refresh() {
        populate();
    }

    public void clear() {
        locations.clear();
        populate();
    }

    public List<OverlayItem> getItems() {
        return locations;
    }
}
